package com.fas.system.controller;

import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.domain.entity.SysDept;
import com.fas.common.core.domain.model.LoginUser;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.utils.SecurityUtils;
import com.fas.system.domain.FasFireHydrant;
import com.fas.system.service.IFasFireHydrantService;
import com.fas.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 消火栓设备信息Controller
 *
 * @date 2022-06-28
 */
@Api(tags = "消火栓设备信息")
@RestController
@RequestMapping("/system/firehydrant")
public class FasFireHydrantController extends BaseController {

    @Resource
    private IFasFireHydrantService fasFireHydrantService;
    @Resource
    private ISysDeptService deptService;

    @ApiOperation(value = "总公司查询消火栓设备")
//    @PreAuthorize("@ss.hasPermi('system:equipment:ceshi')")
    @GetMapping("/findAllEquipment")
    public TableDataInfo findAllEquipment(FasFireHydrant fasFireHydrant,Integer pageNum,Integer pageSize){
        System.out.println("输入的参数："+ fasFireHydrant.toString());
        LoginUser user = SecurityUtils.getLoginUser();
        SysDept sysDept = deptService.selectDeptById(user.getDeptId());
//        DeptType :  0:总部 1:渠道商 2:维保单位
        if("0".equals(sysDept.getDeptType())){
            startPage();
            List<FasFireHydrant> fasFireHydrantList = fasFireHydrantService.findAllEquipment(fasFireHydrant);
            return getDataTable(fasFireHydrantList);
        }else if("2".equals(sysDept.getDeptType())){
            fasFireHydrant.setDeptId(user.getDeptId());
            startPage();
            List<FasFireHydrant> allEquipment = fasFireHydrantService.findLikeEngineer(fasFireHydrant);
            return getDataTable(allEquipment);
        }
        return null;
    }

    @ApiOperation(value = "新增消火栓设备")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FasFireHydrant fasFireHydrant) {
        LoginUser user = SecurityUtils.getLoginUser();
        fasFireHydrant.setDeptId(user.getDeptId());
        return AjaxResult.success(fasFireHydrantService.insertFasFireHydrant(fasFireHydrant));
    }

    @ApiOperation(value = "修改消火栓设备")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasFireHydrant fasFireHydrant) {
        return AjaxResult.success(fasFireHydrantService.updateFasFireHydrant(fasFireHydrant));
    }

    @ApiOperation(value = "删除消火栓设备")
    @DeleteMapping("/delete/{id}")
    public AjaxResult edit(@PathVariable("id") Integer id) {
        return AjaxResult.success(fasFireHydrantService.deleteFasFireHydrant(id));
    }

}
